<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <!-- <el-form-item label="达人信息表ID" prop="sampleTalentInfoId">
        <el-input v-model="queryParams.sampleTalentInfoId" placeholder="请输入达人信息表ID" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item label="" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="recipient">
        <el-input
          v-model="queryParams.recipient"
          placeholder="请输入收件人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入收件人地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="逻辑删除;0=未删除；1=已删除" prop="isDelete">
        <el-input v-model="queryParams.isDelete" placeholder="请输入逻辑删除;0=未删除；1=已删除" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['product:contact:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['product:contact:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['product:contact:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          size="mini"
          plain
          icon="el-icon-plus"
          @click="handeiscontactList"
          >批量寄样</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button size="mini" plain @click="chatVFU">内部寄样</el-button>
      </el-col>
      <!-- icon="el-icon-plus" -->
      <el-col :span="1.5">
        <el-button
          size="mini"
          plain
          @click="chatReturn"
          v-hasPermi="['product:sampleApply:returnApply']"
          >发起退货</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <!-- 添加或修改产品一级信息对话框  @close="handleClose"-->
    <el-dialog
      :visible.sync="iscontactList"
      width="95%"
      height="100%"
      append-to-body
      v-if="iscontactList"
    >
      <Add :contactList="list" :sampleTalentCooperateType="'VFU'" />
    </el-dialog>

    <div ref="tableDom">
      <el-table
        :maxHeight="contactList.length ? tableHeight : 'auto'"
        v-loading="loading"
        :data="contactList"
        @selection-change="handleSelectionChange"
        @row-dblclick="t"
        @cell-click="tableEdit"
        ref="table"
      >
        <el-table-column type="selection" width="55" align="center" />
        <!-- <el-table-column label="联系ID" align="center" prop="id" />
      <el-table-column label="达人信息表ID" align="center" prop="sampleTalentInfoId" /> -->
        <!-- <el-table-column label="平台ID" align="center" prop="platformId" />
      <el-table-column label="昵称" align="center" prop="xhsNickname" /> -->
        <el-table-column label="收件人" align="center" prop="recipient" />
        <el-table-column label="电话" align="center" prop="phone" />

        <el-table-column label="收货省份" align="center" prop="receiverState" />
        <el-table-column label="收货市" align="center" prop="receiverCity" />
        <el-table-column
          label="收货区"
          align="center"
          prop="receiverDistrict"
        />

        <el-table-column label="收件人地址" align="center" prop="address" />
        <!-- :formatter="formatData"  -->
        <el-table-column label="备注" align="center" prop="remark" />
        <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['product:contact:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['product:contact:remove']">删除</el-button>
        </template>
      </el-table-column> -->
      </el-table>
    </div>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改联系方式对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        label-width="100px"
        :inline="true"
      >
        <!-- <el-form-item label="达人信息表ID" prop="sampleTalentInfoId">
          <el-input v-model="form.sampleTalentInfoId" placeholder="请输入达人信息表ID" />
        </el-form-item> -->
        <el-form-item label="收件人" prop="recipient">
          <el-input v-model="form.recipient" placeholder="请输入收件人" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>

        <el-form-item label="所在区域" prop="">
          <el-row>
            <!-- <el-select v-model="form.receiverState" placeholder="请选择" @change="selectProvimce" style="width:130px">
              <el-option v-for="(item, index) of provincearr" :key="index" :label="item.name"
                :value="item.name"></el-option>
            </el-select>
            <el-select v-model="form.receiverCity" placeholder="请选择" @change="selectcity" style="width:130px">
              <el-option v-for="(item, index) of cityarr" :key="index" :label="item.name" :value="item.name"></el-option>
            </el-select>
            <el-select placeholder="请选择" v-model="form.receiverDistrict" style="width:150px">
              <el-option v-for="(item, index) of regionarr" :key="index" :label="item.name"
                :value="item.name"></el-option>
            </el-select> -->
            <el-select
              v-model="form.receiverState"
              clearable
              placeholder="省"
              @change="seletekey($event, 'province')"
              style="width: 130px"
            >
              <el-option
                v-for="(val, key) in provinces"
                :key="key"
                :label="val"
                :value="val"
              />
            </el-select>
            <el-select
              v-model="form.receiverCity"
              clearable
              placeholder="市"
              @change="seletekey($event, 'city')"
              style="width: 130px"
            >
              <el-option
                v-for="(val, key) in citys"
                :key="key"
                :label="val"
                :value="val"
              />
            </el-select>
            <el-select
              v-model="form.receiverDistrict"
              clearable
              placeholder="县区"
              @change="seletekey($event, 'area')"
              style="width: 150px"
              filterable
              allow-create
            >
              <el-option
                v-for="(val, key) in areas"
                :key="key"
                :label="val"
                :value="val"
              />
            </el-select>
          </el-row>
        </el-form-item>
        <el-form-item label="收件人地址" prop="address">
          <el-input
            v-model="form.address"
            placeholder="请输入收件人地址"
            style="width: 300px"
          />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="备注" />
        </el-form-item>
        <el-form-item label="文本粘贴" prop="">
          <el-input
            v-model="demo"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 10 }"
            placeholder="省市区地址、姓名、电话11位用空格分开!!"
            style="width: 350px"
          ></el-input>
          <el-button type="primary" size="mini" @click="addText"
            >识别</el-button
          >
          <!-- <el-input v-model="sampleTalentPay.platform" placeholder="请输入平台名称" /> -->
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 内部寄样 -->
    <el-dialog
      :visible.sync="VisibleVFU"
      append-to-body
      title="内部寄样"
      width="650px"
      v-if="VisibleVFU"
    >
      <el-form
        ref="formVFU"
        :model="formVFU"
        :rules="rules"
        label-width="110px"
        :inline="true"
      >
        <!-- <el-form-item label="请选择收件地址" prop="address">
<el-select v-model="formVFU.id">
<el-option v-for="item in optionsContact" :key="item.id"
  :label="`${item.recipient},${item.phone},${item.address}`" :value="item.id" />
</el-select>
</el-form-item> -->
        <el-form-item label="是否归还" prop="isReturn">
          <!-- <el-input v-model="formVFU.isReturn" placeholder="是否归还" /> -->
          <el-select
            v-model="formVFU.isReturn"
            placeholder="请选择是否归还"
            clearable
            filterable
          >
            <el-option
              v-for="dict in dict.type.sys_one_zero"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="快递公司" prop="expressCompany">
          <!-- <el-input v-model="formVFU.expressCompany" placeholder="快递公司" /> -->
          <el-select
            v-model="formVFU.expressCompany"
            placeholder="请选择快递公司"
            clearable
            filterable
          >
            <el-option
              v-for="dict in dict.type.sys_jst_sample_sf"
              :key="dict.label"
              :label="dict.label"
              :value="dict.label"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="发货备注" prop="applyReson">
          <el-input
            v-model="formVFU.applyReson"
            placeholder="发货备注"
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 12 }"
            :style="{ width: '100%' }"
          />
          <!-- <el-select v-model="formVFU.isReturn" placeholder="请选择是否归还" clearable filterable>
      <el-option v-for="dict in dict.type.sys_one_zero" :key="dict.value" :label="dict.label" :value="dict.label" />
    </el-select> -->
        </el-form-item>
        <el-form-item label="直播间名称" prop="liveRoomName">
          <!-- <el-input
                :disabled="to_sumbit"
                v-model="form.liveRoomName"
                placeholder="请输入直播间名称"
              /> -->
          <el-select
            v-model="formVFU.liveRoomName"
            clearable
            placeholder="直播间名称"
            filterable
          >
            <el-option
              v-for="(val, key) in liveroomList"
              :key="key"
              :label="val.liveStreamRoom"
              :value="val.liveStreamRoom"
            />
          </el-select>
        </el-form-item>
        <el-row v-for="(noticItem, index) in colorProperty" :key="index">
          <el-col>
            <el-form-item label="寄样款式" prop="colorProperty">
              <!-- <el-input v-model="noticItem.value" placeholder="请输入颜色属性" /> -->
              <el-select
                v-model="noticItem.value"
                clearable
                filterable
                remote
                :remote-method="getData"
                :loading="loading"
                placeholder="寄样款式"
              >
                <el-option
                  v-for="item in productNooptions"
                  :key="item"
                  :label="item"
                  :value="item"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-button type="primary" size="mini" @click="addVFU"
              >新增</el-button
            >
            <el-button
              type="danger"
              size="mini"
              @click.prevent="removeVFU(noticItem)"
              >删除</el-button
            >
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-top: 50px">
        <el-button type="primary" @click="submitVFU">确 定</el-button>
        <!-- <el-button @click="canNew">取 消</el-button> -->
        <!-- <el-button @click="addVFU">新增</el-button> -->
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="Visiblereturn"
      append-to-body
      title="发起退货"
      width="500px"
      v-if="Visiblereturn"
    >
      <el-form
        ref="fReturn"
        :model="fReturn"
        :rules="rules"
        label-width="110px"
        :inline="true"
      >
        <!-- <el-form-item label="取件地址" prop="returnAddress" v-show="noSelf">
          <el-select v-model="fReturn.returnContactId">
            <el-option
              v-for="item in optionsContact"
              :key="item.id"
              :label="`${item.phone},${item.recipient},${item.receiverState}${item.receiverCity}${item.receiverDistrict}${item.address}`"
              :value="item.id"
            />
          </el-select>
        </el-form-item> -->
        <!-- <el-form-item label="寄出方式" prop="returnAddress">
          <el-radio-group
            v-model="state"
            size="small"
            fill="#66b1ff"
            @change="changeState"
          >
            <el-radio :label="0">上门取件</el-radio>
            <el-radio :label="1">自行寄出</el-radio>
          </el-radio-group>
        </el-form-item> -->

        <el-form-item label="仓库地址" prop="returnAddress" v-show="noSelf">
          <el-select
            @focus="onFocus"
            v-model="fReturn.sampleReturnAddressId"
            clearable
            filterable
            remote
            :remote-method="changeAddress"
          >
            <el-option
              v-for="item in returnAddressList"
              :key="item.id"
              :label="`${item.returnName},${item.returnPhone},${item.returnAddress}`"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="预约日期" prop="pickupDayType" v-show="noSelf">
          <el-select
            v-model="fReturn.pickupDayType"
            placeholder="请选择预约时间"
            clearable
          >
            <el-option
              v-for="dict in dict.type.sys_sample_day"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="上门时间" prop="returnDate" v-show="noSelf">
          <el-select
            v-model="returnDate"
            placeholder="请选择上门时间"
            clearable
          >
            <el-option
              v-for="dict in dict.type.sys_sample_time"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="快递公司" prop="expressCompany">
          <!-- <el-input v-model="Contact.expressCompany" placeholder="快递公司" /> -->
          <el-select
            v-model="fReturn.expressCompany"
            placeholder="请选择快递公司"
            clearable
            filterable
            v-if="noSelf"
          >
            <el-option
              v-for="dict in dict.type.sys_sample_sf"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            />
          </el-select>
          <el-select
            v-model="fReturn.expressCompany"
            placeholder="请选择快递公司"
            clearable
            filterable
            v-if="!noSelf"
          >
            <el-option
              v-for="dict in dict.type.sys_jst_sample_sf"
              :key="dict.label"
              :label="dict.label"
              :value="dict.label"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="退货快递单号" prop="address" v-show="!noSelf">
          <!-- <el-select v-model="formSelf.id">
      <el-option v-for="item in optionsContact" :key="item.id" :label="item.address" :value="item.id" />
    </el-select> -->
          <el-input
            v-model="fReturn.expressNumber"
            placeholder="请输入退货快递单号"
            oninput="value=value.replace(/[^0-9A-Za-z]/g,'')"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-top: 50px">
        <el-button type="primary" @click="submitReturn" v-show="noSelf"
          >确 定</el-button
        >
        <el-button type="primary" @click="submitSelf" v-show="!noSelf"
          >确 定</el-button
        >
        <!-- <el-button @click="canNew">取 消</el-button> -->
        <el-button @click="Return">取消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :visible.sync="VisibleLive"
      append-to-body
      title="直播合作"
      width="900px"
      v-if="VisibleLive"
    >
      <el-form
        ref="fLive"
        :model="fLive"
        :rules="rules"
        label-width="110px"
        :inline="true"
      >
        <el-form-item label="是否归还" prop="isReturn">
          <!-- <el-input v-model="formVFU.isReturn" placeholder="是否归还" /> -->
          <el-select
            v-model="fLive.isReturn"
            placeholder="请选择是否归还"
            clearable
            filterable
          >
            <el-option
              v-for="dict in dict.type.sys_one_zero"
              :key="dict.value"
              :label="dict.label"
              :value="dict.label"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="快递公司" prop="expressCompany">
          <!-- <el-input v-model="formVFU.expressCompany" placeholder="快递公司" /> -->
          <el-select
            v-model="fLive.expressCompany"
            placeholder="请选择快递公司"
            clearable
            filterable
          >
            <el-option
              v-for="dict in dict.type.sys_jst_sample_sf"
              :key="dict.label"
              :label="dict.label"
              :value="dict.label"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="选择款式" prop="">
          <el-select
            v-model="fLive.productNo"
            clearable
            filterable
            remote
            :remote-method="getDatas"
            :loading="loading"
            placeholder="货号编码"
            @change="testAdd(fLive.productNo)"
            style="width: 150px"
          >
            <el-option
              v-for="item in options"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
          <el-select
            ref="selectRef"
            v-model="fLive.colorProperty"
            clearable
            filterable
            placeholder="选择颜色"
            @change="testColor(fLive.productNo, fLive.colorProperty)"
            style="width: 200px"
          >
            <el-option
              v-for="item in ColorLike"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
          <el-select
            ref="multiSelect"
            v-model="fLive.size"
            clearable
            placeholder="尺寸"
            style="width: 100px"
            @change="testSize(fLive.productNo, fLive.colorProperty, fLive.size)"
          >
            <!--    -->
            <el-option
              v-for="item in sizeList"
              :key="item.id"
              :label="item.size"
              :value="item.size"
            >
            </el-option>
          </el-select>
          <el-input
            ref="autoFocus"
            v-model="fLive.applyNum"
            placeholder="购买数量"
            style="width: 110px"
            type="number"
            oninput="value=value.replace(/^0|[^0-9]/g,'')"
          ></el-input>
        </el-form-item>
        <el-form-item prop="num" label="库存量:" label-width="70px">
          <!-- {{ sizeArr[index] }} -->
          <!-- <div v-for="(item) in sizeArr">

                               
                            </div> -->
          <!-- {{ nameItem.id }} -->

          {{ sizeArr }}
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-top: 50px">
        <el-button type="primary" @click="submitLive('fLive')">确 定</el-button>
        <!-- <el-button @click="canNew">取 消</el-button> -->
        <!-- <el-button @click="addDomain">新增</el-button> -->
      </div>
    </el-dialog>
  </div>
</template>

<script>
import AddressParse from "address-parse";
import {
  listReturnAddress,
  getReturnAddress,
  delReturnAddress,
  addReturnAddress,
  updateReturnAddress,
  search,
} from "@/api/sample/returnAddress";
//数据获取
import { pcaa } from "area-data";
import { getInfo } from "@/api/login.js";
import axios from "axios";
// import { province } from '@/api/sample/map'
import {
  listInnerContact,
  getContact,
  delContact,
  addContact,
  updateContact,
} from "@/api/sample/contact";
import {
  listTemplate,
  getTemplate,
  delTemplate,
  addTemplate,
  updateTemplate,
  addTemplateAndSecondry,
  addProNoColorSize,
  productNoLike,
} from "@/api/product/template";
import {
  listSecondry,
  getSecondry,
  delSecondry,
  addSecondry,
  updateSecondry,
  getInfoByName,
  productNoColorLike,
  listAll,
} from "@/api/product/secondry";
import {
  listSampleApply,
  getSampleApply,
  delSampleApply,
  addSampleApply,
  updateSampleApply,
  addApply,
  returnApply,
  addInnerApply,
  addInnerContact,
  pickupApply,
} from "@/api/sample/sampleApply";
import {
  listSample,
  getSample,
  delSample,
  addSample,
  updateSample,
  SampleTalentFirstAdd,
  inventory,
} from "@/api/sample/sample";
// import { listContact, getContact, delContact, addContact, updateContact } from "@/api/sample/contact";
import { listPay, getPay, delPay, addPay, updatePay } from "@/api/sample/pay";
import { batchAdd } from "@/api/sample/live";
import {
  listNote,
  getNote,
  delNote,
  addNote,
  updateNote,
} from "@/api/sample/note";
import Add from "@/views/sample/Add/Add.vue";
//--------导入token
import { getToken } from "@/utils/auth";
import {
  listLiveroom,
  getLiveroom,
  delLiveroom,
  addLiveroom,
  updateLiveroom,
} from "@/api/sample/liveroom";
export default {
  name: "Contact",
  dicts: [
    "sys_product_qudao",
    "sys_sample_status",
    "sys_sample_sf",
    "sys_one_zero",
    "sys_sample_day",
    "sys_sample_time",
    "sys_sample_name",
    "sys_sample_cj",
    "sys_jst_sample_sf",
  ],
  components: {
    Add,
  },
  data() {
    return {
      liveroomList: [],
      //一键寄样
      iscontactList: false,
      sizeArr: "",
      //模糊匹配
      sizeList: [],
      ColorLike: [],
      options: [], // 选项，从后端传递过来
      VisibleLive: false,
      fLive: {
        isReturn: "是",

        expressCompany: "中通快递",
        applyNum: 1,
      },
      //选中
      list: [],
      //纵向滚动条
      tableHeight: "",
      //选中get
      sampleTalentInfoId: [],
      //上门取件
      Visiblereturn: false,
      fReturn: {
        pickupDayType: "今天",
        expressCompany: "中通快递",
      },
      returnAddressList: [],
      //上门时间
      returnDate: "15:00-17:00",
      //上门取件or自行寄出
      state: 1,
      noSelf: false,
      VisibleSelf: false,

      //用户id
      userId: "",

      //达人收件信息
      productNooptions: [],
      optionsContact: [],
      formVFU: {
        isReturn: "是",

        expressCompany: "中通快递",
      },
      colorProperty: [{ value: "" }],
      VisibleVFU: false,
      fVFU: {},

      //文本粘贴
      demo: "",
      //省市区
      pcaaData: pcaa,
      // 区域数据
      provinces: pcaa["86"],
      citys: [],
      areas: [],

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 联系方式表格数据
      contactList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sampleTalentInfoId: null,
        phone: null,
        recipient: null,
        address: null,
        isDelete: null,
        // createBy: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        sampleTalentInfoId: [
          { required: true, message: "达人信息表ID不能为空", trigger: "blur" },
        ],
        phone: [{ required: true, message: "电话不能为空", trigger: "blur" }],
      },
    };
  },
  created() {
    listLiveroom({
      pageNum: 1,
      pageSize: 100,
    }).then((response) => {
      response.rows.unshift({ liveStreamRoom: "非直播间申请" });
      this.liveroomList = response.rows;
      // this.total = response.total;
      // this.loading = false;
    });
    var template = JSON.parse(localStorage.getItem("livequeryParams"));
    if (template) {
      // this.$set(this.queryParams, storeForm)
      this.queryParams = template;
    }

    var templateList = JSON.parse(localStorage.getItem("liveList"));
    if (templateList) {
      this.$set(this.queryParams, "pageNum", templateList.currentPage);
      this.$set(this.queryParams, "pageSize", templateList.pageSize);

      this.Nowscroll = templateList.scrollTop;
    }
    this.getroles();
    // this.provincearr = province
  },
  mounted() {
    var _this = this;
    this.resizeTable();
    window.onresize = function () {
      _this.resizeTable();
    };
  },
  methods: {
    // 打开加载层
    openLoading2() {
      this.$modal.loading("正在读取聚水潭库存，请稍侯！");
    },
    testSize(productNo, colorProperty, size) {
      // var apply = this.noticForm.noticConfig.map((item) => item.name[0]);
      // const hasEmptyProductNo = apply.some(
      //   (product) => product.productNo == ""
      // );
      // if (hasEmptyProductNo) {
      //   this.$modal.msgError("检查货号编码是否为空");
      //   return;
      // }
      // const hasEmptycolorProperty = apply.some(
      //   (product) => product.colorProperty == ""
      // );
      // if (hasEmptycolorProperty) {
      //   this.$modal.msgError("检查颜色属性是否为空");
      //   return;
      // }
      // const hasEmptysize = apply.some((product) => product.size == "");
      // if (hasEmptysize) {
      //   this.$modal.msgError("检查尺寸是否为空");
      //   return;
      // }
      // console.log(JSON.stringify(key));
      // this.size = key;
      // console.log(this.count);
      // console.log(index);
      this.openLoading2();
      inventory({
        productNo: productNo,
        colorProperity: colorProperty,
        size: size,
      }).then((res) => {
        this.$modal.closeLoading();

        if (res.code == 200) {
          if (res.data.length > 0) {
            // if (res.data[0].publicCanUseNum < 5) {
            //   this.$alert(
            //     `货号:${this.productNo}，颜色：${this.colorProperty}，码数：${this.size}，库存不足，仅${res.data[0].publicCanUseNum}件，请慎重申请。`,
            //     "温馨提醒",
            //     {
            //       confirmButtonText: "我知道了",
            //       // showConfirmButton: false,
            //     }
            //   ).then(() => {});
            // }
            this.sizeArr = res.data[0].publicCanUseNum;
            // console.log(JSON.stringify(this.sizeArr[index]));
            console.log(JSON.stringify(this.sizeArr));
            this.$forceUpdate();
          } else {
            this.$alert("该商品编码聚水潭不存在，请核对。", "提示", {
              confirmButtonText: "我知道了",
              // showConfirmButton: false,
            }).then(() => {});
            // this.$modal.msgError("该商品编码聚水潭不存在，请核对。");
          }
        } else {
          this.$alert("该商品编码聚水潭不存在，请核对。", "提示", {
            confirmButtonText: "我知道了",
            // showConfirmButton: false,
          }).then(() => {});
          // this.$modal.msgError(res.msg);
        }
      });
      // setTimeout(() => {
      //   this.$refs[multiSelect].blur();
      // }, 50);

      // this.$refs[multiSelect].blur();
    },
    /* 获取尺寸列表 */
    testColor(productNo, colorProperty) {
      listAll({ productNo: productNo, colorProperty: colorProperty }).then(
        (res) => {
          // this.loading = false;
          this.sizeList = res;
          console.log(JSON.stringify(res));
        }
      );
    },
    /* 获取颜色列表 */
    testAdd(key, index) {
      this.productNo = key;
      console.log();
      if (!key) {
        return;
      }
      productNoColorLike({ productNo: key }).then((res) => {
        // this.loading = false;
        this.ColorLike = res.data;
        console.log(JSON.stringify(this.ColorLike));
      });
    },

    /* 获取货号列表 */
    getDatas(key) {
      console.log(JSON.stringify(key));
      this.loading = true;
      // return
      productNoLike(key).then((res) => {
        this.loading = false;
        this.options = res.data;
        console.log(JSON.stringify(this.options));
      });
    },
    chatlive() {
      if (this.ids.length == 0) {
        this.$modal.msgError("请选择一个收件地址！");
        return;
      }
      this.VisibleLive = true;
    },

    //抽奖活动
    submitLive() {
      if (this.ids.length == 0) {
        this.$modal.msgError("请选择一个收件地址！");
        return;
      }
      var live = [];
      console.log(JSON.stringify(this.ids));
      this.list.forEach((item) => {
        live.push({
          contactId: item.id,
          sampleTalentCooperateId: null,
          sampleTalentCooperateType: "live",
          sampleTalentInfoId: item.sampleTalentInfoId,
          ...this.fLive,
        });
      });
      addInnerApply(live).then((response) => {
        this.VisibleLive = false;
        if (response.code == 200) {
          this.$modal.msgSuccess("新增成功");
          this.$router.push({
            path: "/sample/sampleApply",
            // query: { id: this.ids[0] },
          });
        }
      });
    },
    // table自动高度
    returnTableHeight(ref, bottomOffset) {
      let height = null;
      height =
        window.innerHeight - ref.getBoundingClientRect().top - bottomOffset;
      return height;
    },

    resizeTable() {
      this.$nextTick(() => {
        this.tableHeight = this.returnTableHeight(this.$refs.tableDom, 100);
      }, 0);
    },
    //根据当前用户id获取数据
    getroles() {
      // var userId = null
      getInfo().then((res) => {
        console.log(JSON.stringify(res));
        // this.applyname = res.user.dept.deptName + '-' + res.user.nickName

        this.userId = res.user.userId.toString();
        console.log(JSON.stringify(typeof this.userId));
        // var dept =
        // this.form.roleName = res.roles[0]

        // this.roleName = res.roles[0]
        // this.$forceUpdate()

        this.$set(this.queryParams, "platform", "VFU");
        this.$set(this.queryParams, "createBy", this.userId);
        this.getList();
        // return res.roles[0]
        // this.$data.queryParams.roleName = res.roles[0]
      });
    },
    //修改对话框
    //添加颜色列表获得焦点
    onFocus() {
      // this.getData();

      // this.getSize();
      this.changeAddress("");
      // if (!this.form.colorProperty) {
      //     this.$selectRef.value.blur() //就是这一句，
      // }
    },
    submitSelf() {
      if (!this.fReturn.expressNumber) {
        this.$modal.msgError("请输入退货快递单号");
        return;
      }
      var formreturn = {
        returnMethod: "selfsending",
        sampleTalentInfoId: this.sampleTalentInfoId[0],
        ...this.fReturn,
      };
      console.log(JSON.stringify(formreturn));
      // return
      axios
        .post(
          process.env.VUE_APP_BASE_API + "/product/sampleApply/returnApply",
          formreturn,
          {
            headers: {
              header: {
                // responseType: "blob"
              },

              Authorization: "Bearer " + getToken(),
              // "Content-Type": "multipart/form-data",
            }, //定义内容格式,很重要
            // timeout: 20000,
          }
        )
        .then((response) => {
          this.Visiblereturn = false;
          if (response.data.code == 200) {
            if (response.data.msg == "操作完成！") {
              this.$modal.msgSuccess("申请成功");
              this.$router.push({
                path: "/sample/returned/sampleReturn",
                query: { sampleTalentInfoId: this.sampleTalentInfoId[0] },
              });
            } else {
              this.$modal.msgError(response.data.msg);
            }
          } else if (response.data.code == 500) {
            this.$alert(response.data.msg, "提示", {
              confirmButtonText: "前往认领",
            }).then(() => {
              this.$router.push({
                path: "/sample/returned/AfterSalesOrder",
                query: { trackingNumber: this.fReturn.expressNumber },
              });
            });
          }
        });
    },
    changeAddress(val) {
      console.log(val);
      search(val).then((response) => {
        console.log(JSON.stringify(response));
        this.returnAddressList = response;
      });
    },
    changeState(val) {
      console.log(val);
      if (val == 0) {
        console.log(0);
        this.fReturn = {};
        // this.fReturn.expressCompany = '中通快递'
        this.noSelf = true;
      } else {
        console.log(1);
        this.fReturn = {};
        // this.fReturn.expressCompany = '中通快递'
        this.noSelf = false;
      }
    },

    //申请退货
    chatReturn(row) {
      if (this.ids.length > 1 || this.ids.length == 0) {
        this.$modal.msgError("请选择一个指定达人信息！");
        return;
      }
      this.Visiblereturn = true;
      // listContact({ sampleTalentInfoId: this.ids[0] }).then((res) => {
      //   if (res.rows.length == 0) {
      //     this.$modal.msgError("请添加达人收件信息！");
      //     return;
      //   } else if (res.rows.length > 0) {
      //     this.optionsContact = res.rows;
      //     console.log(JSON.stringify(this.optionsContact));

      //   }
      // });
    },
    Return() {
      this.Visiblereturn = false;
    },
    submitReturn() {
      // if (!this.fReturn.returnContactId) {
      //   this.$modal.msgError("请选择取件地址");
      //   return;
      // }
      if (!this.fReturn.sampleReturnAddressId) {
        this.$modal.msgError("请选择仓库地址");
        return;
      }
      var pickupStartTime = this.returnDate.split("-")[0];
      var pickupEndTime = this.returnDate.split("-")[1];
      console.log(JSON.stringify(pickupStartTime));
      console.log(JSON.stringify(pickupEndTime));
      var formreturn = {
        returnMethod: "pickup",
        sampleTalentInfoId: this.sampleTalentInfoId[0],
        returnContactId: this.ids[0],
        ...this.fReturn,
        pickupStartTime: pickupStartTime,
        pickupEndTime: pickupEndTime,
      };
      console.log(JSON.stringify(formreturn));
      // return
      returnApply(formreturn).then((response) => {
        if (response.code == 200) {
          if (response.msg == "操作完成！") {
            this.$modal.msgSuccess("申请成功");
            this.$router.push({
              path: "/sample/returned/sampleReturn",
              query: { sampleTalentInfoId: this.sampleTalentInfoId[0] },
            });
          } else {
            this.$modal.msgError(response.msg);
          }
        } else {
          this.$modal.msgError(response.msg);
        }
      });
    },
    /* 获取货号列表 */
    getData(key) {
      console.log(JSON.stringify(key));
      this.loading = true;
      // return
      productNoLike(key).then((res) => {
        this.loading = false;
        this.productNooptions = res.data;
        // console.log(JSON.stringify(this.options));
      });
    },

    // 删除
    removeVFU(item) {
      var index = this.colorProperty.indexOf(item);
      if (index == "0") {
        // 还有一个的时候提示不能删除
        this.$message({
          message: "不能删除了",
          type: "error",
        });
        return false;
      }
      if (index !== -1 && index !== "0") {
        this.colorProperty.splice(index, 1);
      }
    },
    // 表单新增
    addVFU() {
      this.colorProperty.push({
        value: "",
        // key: Date.now()+,
      });
    },
    //el-dialog关闭
    // handleClose() {
    //   // Object.assign(this.$data, this.$options.data())
    //   this.$data = this.$options.data();
    //   this.
    //   this.VisibleVFU = false;
    // },
    //批量添加
    chatVFU(row) {
      if (this.ids.length > 1 || this.ids.length == 0) {
        this.$modal.msgError("请选择一个指定达人信息！");
        return;
      }
      this.VisibleVFU = true;
      return;
      listContact({ sampleTalentInfoId: this.ids[0] }).then((res) => {
        if (res.rows.length == 0) {
          this.$modal.msgError("请添加达人收件信息！");
          return;
        } else if (res.rows.length > 0) {
          this.optionsContact = res.rows;
          console.log(JSON.stringify(this.optionsContact));
        }
      });
    },
    //批量添加
    submitVFU() {
      // this.fLive.sampleTalentInfoId = this.ids[0]
      let label = [];
      this.colorProperty.forEach((item) => {
        //判断条件 货号不能为空
        if (label.indexOf(item.value) == -1 && item.value !== "") {
          label.push({
            productNo: item.value,
            sampleTalentInfoId: this.sampleTalentInfoId[0],
            sampleTalentCooperateId: null,
            sampleTalentCooperateType: "VFU",
            contactId: this.ids[0],
            ...this.formVFU,
          });
        }
      });
      if (label.length == 0) {
        this.$modal.msgError("请选择至少一个合作款式！");
        return;
      }
      this.formVFU = label;
      // console.log(JSON.stringify(this.fLive.sampleTalentTemplateList));
      console.log(JSON.stringify(this.formVFU));
      // return
      this.$refs["formVFU"].validate((valid) => {
        if (valid) {
          addInnerApply(this.formVFU).then((response) => {
            if (response.code == 200) {
              this.$modal.msgSuccess("申请成功");

              // this.getList();
              // this.fAdd.colorProperty = []
              this.VisibleVFU = false;
              this.$router.push({ path: "/sample/sampleApply" });
              // , query: { id: this.ids[0] }
              // Object.assign(this.$data, this.$options.data());
            } else {
              this.$modal.msgError("新增失败！");
              Object.assign(this.$data, this.$options.data());
              this.VisibleVFU = false;
              this.getList();
            }
          });
        }
      });
    },
    addText() {
      if (!this.demo) {
        this.$modal.msgError("请输入内容");
        return;
      }
      let address = this.demo.replace(/\s+/g, " ");
      console.log(JSON.stringify(address));
      const result = AddressParse.parse(address);

      this.form.phone = result[0].mobile ? result[0].mobile : "";
      this.form.recipient = result[0].name ? result[0].name : "";
      this.form.receiverState = result[0].province ? result[0].province : "";
      this.form.receiverCity = result[0].city ? result[0].city : "";
      this.form.receiverDistrict = result[0].area ? result[0].area : "";
      this.form.address = result[0].details;
      this.seletekey(this.form.receiverState, "province");
      this.seletekey(this.form.receiverCity, "city");
      this.seletekey(this.form.receiverDistrict, "area");

      let obj = {
        fullAddress: this.demo,
        province: this.form.receiverState,
        city: this.form.receiverCity,
        district: this.form.receiverDistrict,
        detailedAddress: this.form.address,

        recipientPhone: this.form.phone,
        recipientName: this.form.recipient,
      };

      axios({
        method: "post",
        url: "http://47.107.129.160:9001/prod-api/product/parsing",
        // url: "http://47.97.123.182:1399/smAddress",
        data: obj,
      }).then((response) => {});
      // axios({
      //   method: "post",
      //   url: "https://wangzc.wang/smAddress",
      //   // url: "http://47.97.123.182:1399/smAddress",
      //   data: {
      //     address: address,
      //   },
      // }).then((res) => {
      //   // console.log(JSON.stringify(res.data));
      //   this.form.phone = res.data.phone ? res.data.phone : "";
      //   this.form.recipient = res.data.name ? res.data.name : "";
      //   this.form.receiverState = res.data.province ? res.data.province : "";
      //   this.form.receiverCity = res.data.city ? res.data.city : "";
      //   this.form.receiverDistrict = res.data.county ? res.data.county : "";
      //   this.form.address = res.data.street
      //     ? res.data.street + res.data.address
      //     : res.data.address;
      //   this.seletekey(this.form.receiverState, "province");
      //   this.seletekey(this.form.receiverCity, "city");
      //   this.seletekey(this.form.receiverDistrict, "area");
      // });
    },
    seletekey(e, type) {
      if (e) {
        switch (type) {
          case "province":
            Object.keys(this.provinces).filter((item) => {
              if (this.provinces[item] === e) {
                this.citys = this.pcaaData[item];
              }
            });
            break;
          case "city":
            Object.keys(this.citys).filter((item) => {
              if (this.citys[item] === e) {
                this.areas = this.pcaaData[item];
              }
            });
            break;
          case "area":
            this.form.receiverDistrict = e;
            this.$forceUpdate();
            break;
        }
      }
    },
    //点击某一行
    t(row, column, cell, event) {
      console.log(row, column, cell, event);
      this.handleUpdate(row);
    },
    formatData(row) {
      console.log(JSON.stringify(row));
      // let rowPerson = (row) || [];
      // let arr = [];
      // rowPerson.forEach(item => {
      //   //如果数据特别多的话,还可以在这里加if判断,仅展示规定的数据
      //   arr.push(item.size);
      // });
      //
      return (
        row.receiverState +
        row.receiverCity +
        row.receiverDistrict +
        row.address
      );
    },
    /** 查询联系方式列表 */
    getList() {
      let queryParam = null;

      queryParam = this.$route.query.id;

      // console.log();

      this.loading = true;
      console.log(JSON.stringify(this.queryParams));
      // { createBy: this.userId, sampleTalentInfoId: queryParam, phone: this.queryParams.phone, recipient: this.queryParams.recipient, address: this.queryParams.address }
      listInnerContact(this.queryParams).then((response) => {
        this.contactList = response.rows;
        console.log(JSON.stringify(this.contactList));
        setTimeout(() => {
          this.$refs["table"].bodyWrapper.scrollTop = this.Nowscroll;
        }, 13);
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sampleTalentInfoId: null,
        phone: null,
        recipient: null,
        address: null,
        isDelete: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        platform: "VFU",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getroles();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      localStorage.removeItem("liveList");
      localStorage.removeItem("livequeryParams");
      this.queryParams = {};
      this.handleQuery();
    },
    tableEdit(row, column, cell, event) {
      // console.log(row);
      let vmEl = this.$refs["table"].$el;
      console.log(vmEl);
      const scrollParent = vmEl.querySelector(".el-table__body-wrapper");
      // this.Nowscroll = scrollParent.scrollTop
      // console.log(this.queryParams);
      console.log(scrollParent.scrollTop);
      // return
      var templateList = {
        currentPage: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
        scrollTop: scrollParent.scrollTop,

        // "productNo": this.queryParams.productNo,
        // "colorProperty": this.queryParams.colorProperty,
        // "manufacturerCode": this.queryParams.manufacturerCode,
        // "procureRemark": this.queryParams.procureRemark
      };
      localStorage.setItem("liveList", JSON.stringify(templateList));
      localStorage.setItem("livequeryParams", JSON.stringify(this.queryParams));
    },
    //一键寄样
    handeiscontactList() {
      if (this.list.length == 0) {
        this.$modal.msgError("请选择一个收件地址！");
        return;
      }
      this.iscontactList = true;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.tableEdit();
      this.ids = selection.map((item) => item.id);
      this.list = selection.map((item) => item);
      this.sampleTalentInfoId = selection.map(
        (item) => item.sampleTalentInfoId
      );
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      // if (!this.$route.query.id) {
      //   this.$modal.msgError("禁止添加,请从达人信息菜单-联系配置进入");
      //   return
      // }
      this.reset();
      this.open = true;
      this.title = "添加联系方式";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getContact(id).then((response) => {
        this.form = response.data;
        this.seletekey(this.form.receiverState, "province");
        this.seletekey(this.form.receiverCity, "city");
        this.seletekey(this.form.receiverDistrict, "area");
        this.open = true;
        this.title = "修改联系方式";
      });
    },
    /** 提交按钮 */
    submitForm() {
      if (!this.form.recipient) {
        this.$modal.msgError("请输入收件人");
        return;
      }
      if (!this.form.receiverState) {
        this.$modal.msgError("请选择收货省份");
        return;
      }
      if (!this.form.receiverCity) {
        this.$modal.msgError("请选择收货城市");
        return;
      }
      if (!this.form.receiverDistrict) {
        this.$modal.msgError("请选择收货管辖区");
        return;
      }
      if (!this.form.address) {
        this.$modal.msgError("请输入收件人地址");
        return;
      }
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateContact(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.sampleTalentInfoId = this.$route.query.id;
            addInnerContact(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否删除该地址？")
        .then(function () {
          return delContact(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "product/contact/export",
        {
          ...this.queryParams,
        },
        `contact_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
